package br.ufpb.di.ppgi.apresentacao;

import javax.servlet.http.HttpServletRequest;

import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.view.AcceptHeaderToFormat;
import br.com.caelum.vraptor.view.DefaultPathResolver;

@Component
public class CustomPathResolver extends DefaultPathResolver {

	public CustomPathResolver(HttpServletRequest request,
			AcceptHeaderToFormat acceptHeaderToFormat) {
		
		super(request, acceptHeaderToFormat);
	}

	@Override
	protected String getPrefix() {
		return "/WEB-INF/jsp/";
	}

	@Override
	protected String getExtension() {
		return "jsp";
	}

	@Override
    protected String extractControllerFromName(String baseName) {
        baseName = lowerFirstCharacter(baseName);
        
        if (baseName.endsWith("RestrictController")) {
        	return "admin/"+baseName.substring(0, baseName.lastIndexOf("RestrictController"));
        }
        else if (baseName.endsWith("Controller")) {
            return baseName.substring(0, baseName.lastIndexOf("Controller"));
        }
        return baseName;
    }
	
    private String lowerFirstCharacter(String baseName) {
        return baseName.toLowerCase().substring(0, 1) + baseName.substring(1, baseName.length());
    }	

}